package org.example.cet.demos.service.impl;

import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import lombok.RequiredArgsConstructor;
import org.example.cet.demos.domain.PageBean;
import org.example.cet.demos.domain.po.ScoreBank;
import org.example.cet.demos.domain.query.ScoreBankQuery;
import org.example.cet.demos.mapper.ScoreBankMapper;
import org.example.cet.demos.service.IScoreBankService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author hq
 * @since 2024-12-18
 */
@Service
@RequiredArgsConstructor

public class ScoreBankServiceImpl extends ServiceImpl<ScoreBankMapper, ScoreBank> implements IScoreBankService {

    public PageBean getPage(ScoreBankQuery scoreBankQuery) {
        Page<ScoreBank> page = new Page<>(scoreBankQuery.getCurrentPage(), scoreBankQuery.getPageSize());
        lambdaQuery().like(scoreBankQuery.getId()!=null,ScoreBank::getId, scoreBankQuery.getId())
                .like(scoreBankQuery.getStu_id()!=null, ScoreBank::getStu_id, scoreBankQuery.getStu_id())
                .like(scoreBankQuery.getType()!=null, ScoreBank::getType, scoreBankQuery.getType())
                .like(!StrUtil.isBlankIfStr(scoreBankQuery.getScore()), ScoreBank::getScore, scoreBankQuery.getScore())
                .page(page);
        PageBean pageBean = new PageBean();
        pageBean.setTotal(page.getTotal());
        pageBean.setRows(page.getRecords());
        return pageBean;
    }

    @Autowired
    private ScoreBankMapper scoreBankMapper;
    public void insert(String bankId, String stuId, Integer type, double score) {
        scoreBankMapper.insert(bankId, stuId, type, score);
    }
}
